﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smartec.Accounts.Camel.AMS.Model.Entities;
using Smartec.Accounts.Camel.AMS.Model.Facades;
using Smartec.Accounts.Camel.AMS.Model.Managers;

namespace Smartec.Accounts.Camel.AMS.WebApp.Controllers
{
    [Authorize]
    public class RegisteredController : Controller
    {
        //
        // GET: /Registered/

        public ActionResult Index()
        {
            List<Registered> registereds = RegisteredFacade.GetAllRegistered();
            return View(registereds);
        }

        //
        // GET: /Registered/Details/5

        public ActionResult Details(int id)
        {
            Registered registered = RegisteredFacade.GetRegisteredById(id);
            return View(registered);
        }

        //
        // GET: /Registered/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Registered/Create

        [HttpPost]
        public ActionResult Create(Registered registered)
        {
            try
            {
                // TODO: Add insert logic here
                registered.Guid = Guid.NewGuid();
                RegisteredFacade.AddRegestered(registered);
                RegisteredFacade.Save(); 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Registered/Edit/5
 
        public ActionResult Edit(int id)
        {
            Registered registered = RegisteredFacade.GetRegisteredById(id);
            return View(registered);
        }

        //
        // POST: /Registered/Edit/5

        [HttpPost]
        public ActionResult Edit(int id,Registered registered)
        {
            try
            {
                // TODO: Add update logic here
                RegisteredFacade.UpdateRegistered(registered);
                RegisteredFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Registered/Delete/5
 
        public ActionResult Delete(int id)
        {
            Registered registered = RegisteredFacade.GetRegisteredById(id);
            return View(registered);
        }

        //
        // POST: /Registered/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, Registered registered)
        {
            try
            {
                // TODO: Add delete logic here
                RegisteredFacade.DeleteRegisteredById(id);
                RegisteredFacade.Save();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
